<?php
/*=============================================================================
|| ##################################################################
||	phpFoX Konsort
|| ##################################################################
||	
||	Copyright		: (C) 2005-2007 PHPFOX Limited a Reality Fox Creation
||	Contact			: info@phpfox.com
||
||	- phpFoX and all of its source code and files are protected by Copyright Laws. 
||
||	- The license for phpFoX permits you to install this software on a single domain (.com, .org, .net, etc.). 
||
||	- You may also not remove this copyright screen which shows the copyright information and credits for phpFoX (RealityFOX Creations). 
||
||	- phpFoX Konsort is NOT a FREE software - http://www.phpfox.com/license/
||
|| ##################################################################
=============================================================================*/

/* $File: ./include/modules/Site/classes/PhpFox_ComponentStyleLogo.class.php, $Author:  $ */



/** Component for uploading style logo
 * @version $Id: PhpFox_ComponentStyleLogo.class.php 46 2007-12-14 23:12:21Z phpfoxsv $
 * @package module.site
 *   
 */
class PhpFox_Mod_Site_ComponentStyleLogo extends BaseComponent
{
    function process()
    {
        $oReq = &App::getRequest();
        $oTpl = &$this->_oModule->getTemplate();
        $oCssItem = &$this->_oModule->getItem('Css');
        /* @var $oCssItem PhpFox_Mod_Site_ItemCss */
        $oSecurityService = &App::getModuleService('Account', 'Security');
        /* @var $oSecurityService PhpFox_Mod_Account_ServiceSecurity */
        if (!$oSecurityService->hasStaffPerm('MENU_css_default'))
        {
            App::gotoUrl('admin.main');
        }

        $iStyleId = $oReq->getInt('id');
        if (!$oCssItem->load($iStyleId))
        {
            exit();
        }
        if ($oReq->getAction() == 'upload')
        {
            App::loadClass('file/Image');
            $oImage = &new file_Image();
            $sDestPath = App::getParam('style.path').$oCssItem->aData['file'].'/';
            $aParams = array
            (
                'id' => $iStyleId,
            );
            
            $sExt = explode(".",App::getSetting('default_logo_name'));           
            if ($oImage->upload('image', $sDestPath, 'logo', $sExt[1]))
            {
                if (!$oImage->_checkLimits())
                {
                    App::gotoUrl('admin.popup.stylelogo', $aParams, $oImage->getErrors(), 'true');
                }
                App::gotoUrl('admin.popup.stylelogo', $aParams, App::format('Mod_Site.info.file_uploaded'));
            }
        }
        $sStyleUrl = App::getParam('style.url').$oCssItem->aData['file'].'/'. App::getSetting('default_logo_name') .'';
        $sStylePath = App::getParam('style.path').$oCssItem->aData['file'].'/'. App::getSetting('default_logo_name') .'';
        $oTpl->assign(array(
            'sStyleUrl'  => $sStyleUrl,
            'iStyleId'   => $iStyleId,
            'bWritable'  => CFile::isWritable($sStylePath),
            'sStyleName' => $oCssItem->aData['name'],
        ));
        return $oTpl->fetch('StyleLogo.html');
    }
}
?>